home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_084 / ed / ins.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  977b  |  52 lines

  1. /*
  2.  * Copyright 1987 Brian Beattie Rights Reserved.
  3.  *
  4.  * Permission to copy and/or distribute granted under the
  5.  * following conditions:
  6.  *
  7.  * 1). No charge may be made other than resonable charges
  8.  *    for reproduction.
  9.  *
  10.  * 2). This notice must remain intact.
  11.  *
  12.  * 3). No further restrictions may be added.
  13.  *
  14.  */
  15. #include <stdio.h>
  16. #include "tools.h"
  17. #include "ed.h"
  18.  
  19. ins(str)
  20. char    *str;
  21. {
  22.     char    buf[MAXLINE], *cp;
  23.     LINE    *new, *cur, *nxt;
  24.  
  25.     cp = buf;
  26.     while(1)
  27.     {
  28.         if((*cp = *str++) == NL)
  29.             *cp = EOS;
  30.         if(*cp)
  31.         {
  32.             cp++;
  33.             continue;
  34.         }
  35.         if((new = (LINE *)malloc(sizeof(LINE)+strlen(buf))) == NULL)
  36.             return( ERR );     /* no memory */
  37.  
  38.         strcpy(new->l_buff,buf);    /* build new line */
  39.         cur = getptr(curln);        /* get current line */
  40.         nxt = getptr(nextln(curln));    /* get next line */
  41.         relink(cur, new, new, nxt);    /* add to linked list */
  42.         relink(new, nxt, cur, new);
  43.         lastln++;
  44.         curln++;
  45.  
  46.         if(*str == EOS)        /* end of line ? */
  47.             return( 1 );
  48.  
  49.         cp = buf;
  50.     }
  51. }
  52.